﻿using System;
using System.IO;

using MbUnit.Framework;

namespace Abstract2ion.Tests
{
	public class FileItemTestFixture : FileSystemTestFixtureBase
	{
		[Test]
		public void CanCreateFileItemFromPath()
		{
			var fileItem = new FileItem(FirstFilePath);

			Assert.AreEqual(FirstFileName, fileItem.Name);
			Assert.AreEqual(FirstFilePath, fileItem.FullName);
		}

		[Test]
		public void CanCreateFileItemFromFileInfo()
		{
			var fileItem = new FileItem(new FileInfo(FirstFilePath));

			Assert.AreEqual(FirstFileName, fileItem.Name);
			Assert.AreEqual(FirstFilePath, fileItem.FullName);
		}

		[Test]
		public void CanGetExtensionFromFileItem()
		{
			var fileItem = new FileItem(new FileInfo(FirstFilePath));

			Assert.AreEqual(FileExtension, fileItem.Extension);
		}

		[Test]
		public void EvaluatesExistsForValidFile()
		{
			var result = new FileItem(FirstFilePath).Exists;

			Assert.IsTrue(result);
		}

		[Test]
		public void EvaluatesExistsForInvalidFile()
		{
			var result = new FileItem(InvalidFilePath).Exists;

			Assert.IsFalse(result);
		}

		[Test]
		public void CanGetByteContentOfFile()
		{
			var contentBytes = System.Text.Encoding.ASCII.GetBytes("Test File Content");
			File.WriteAllBytes(FirstFilePath, contentBytes);

			var result = new FileItem(FirstFilePath).ReadAllBytes();

			Assert.AreEqual(contentBytes, result);
		}
	}
}